/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Administrator
 */
public class ParkingSlot <E> {

    private Object[] items;
    private int cont,limit;
    boolean empty = true;

    public ParkingSlot(int l){

        limit = l;
        items = new Object[limit];
        cont = -1;
    }

    public void setItem(E i) throws StackOverflow {
        StackOverflow overflow = new StackOverflow("Ya no hay espacio para almacenar en el stack");

        if(cont < limit){
            cont++;
            items[cont] = i;
        }
        else
        throw overflow;
    }

    public boolean getEmpty(){
        if (cont < 0)
            empty = true;
        else
            empty = false;
        return(empty);
    }

    public E viewItem() throws StackUnderflow {
        StackUnderflow underflow = new StackUnderflow("El stac esta vacio");

        if (!(this.getEmpty()))
            return((E)items[cont]);
        else
            throw underflow;

    }

    public E getItem() throws StackUnderflow {
        StackUnderflow underflow = new StackUnderflow("El stack esta vacio");

        if (!(this.getEmpty())){
            cont--;
            return((E)items[cont+1]);
        }
        else{
            System.out.println("No sta tirando la exception");
            throw underflow;
        }
            
    }

    public int getIndex(){
        return(cont);
    }
}
